Skip to main content

22.03.03 - Layout Managers and Labels

Threads and main()

When window created, a thread will be started, but main() thread will still be running

Example: JLabel

Can use the sub-class object as if it was the super-class. Then overwrite sections, similar to a theme. Such as font etc. Can only call immediate super class

ColorLabel

Has three attributes:

  1. Colour to draw
  2. Width of the border
  3. Colour to draw the border

this - call another instructor of itself

Example Layout Managers

JPanel Components

Container for other components. Can build up a user interface by putting JPanels inside JPanels

Component Size

  • pack() resizes the frame to fit the contents
  • When you resize the frame, sometimes components will resize to fit in
  • Can set, min, max, preferred
  • Layout manager should not make them smaller than min or larger than max
  • When working out what size, will use preferred size
  • When multiple sizes are possiblejop preferred with be 'preferred'

Common Layouts include:

FlowLayout()
BorderLayout()
GridLayout()